module.exports = function sendmsg(obj){
    var data = obj;
    var request = require("request");
    var MongoClient = require('mongodb').MongoClient;
    var DB_CONN_STR = 'mongodb://weixinpc:Weixinpc*/66.@localhost:27017/weixin';
    // var DB_CONN_STR = 'mongodb://localhost:27017/weixin';
    var selectData = function(db, callback) {
        var collection = db.collection('site');
        var whereStr = {"order":'111'};
        collection.find(whereStr).toArray(function(err, result) {
            if(err)
            {
                console.log('Error:'+ err);
                return;
            }
            accesstoken = result[0].accesstoken;
            callback(result);
        });
    }
    MongoClient.connect(DB_CONN_STR, function(err, db) {
        selectData(db, function(result) {
            db.close();
        });
    });
    setTimeout(function(){
        var url1 = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='+accesstoken;
        var bbb = JSON.stringify(data);
        request.post({url:url1,form:bbb},function(err,res,body){
            if(err){console.log(err)}else{console.log(res.body);}
        })
    },200)
}